package com.sakura.principle.liskov.improve;

/**
 * @Author Sakura
 * @Date 2022/11/9 10:57
 * @Version 1.0
 */
public class LSPtest2 {
    public static void main(String[] args) {
        Bird bird = new Swallow();
        Animal animal = new BrownKiwi();
        bird.setFlySpeed(150);
        animal.setRunSpeed(100);
        System.out.println("如果飞行/奔跑300公里：");
        try {
            System.out.println("燕子将飞行" + bird.getFlyTime(300) + "小时.");
            System.out.println("几维鸟将奔跑" + animal.getFlyTime(300) + "小时。");
        } catch (Exception err) {
            err.printStackTrace();
            System.out.println("发生错误了!");
        }

    }

}

//动物类
class Animal {

    int runSpeed;

    public void setRunSpeed(int speed) {
        runSpeed = speed;
    }

    public double getFlyTime(int distance) {
        return (distance / runSpeed);
    }
}

//鸟类
class Bird {

    int flySpeed;

    public void setFlySpeed(int flySpeed) {
        this.flySpeed = flySpeed;
    }

    public double getFlyTime(int distance) {
        return (distance / flySpeed);
    }
}

//燕子类
class Swallow extends Bird {
}

//几维鸟类
class BrownKiwi extends Animal {

    @Override
    public void setRunSpeed(int speed) {
        runSpeed = speed;
    }
}
